package site.yunnong.atvris.portal.controller;

import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import site.yunnong.atvris.common.api.Page;
import site.yunnong.atvris.common.api.ResultVO;
import site.yunnong.atvris.service.UserHistoryViewService;
import site.yunnong.atvris.common.dto.HistoryViewParam;
import site.yunnong.atvris.common.dto.HistoryViewQueryParam;
import site.yunnong.atvris.service.vo.HistoryViewVO;

import javax.annotation.Resource;


/**
 * 用户视频历史播放
 *
 * @author zhangjinghao
 * @email jhzhang9102@163.com
 * @date 2021-07-09 23:45:37
 */
@RestController
@RequestMapping("/history")
public class UserHistoryViewController {
    
    @Resource
    private UserHistoryViewService userHistoryViewService;

    @ApiOperation("记录视频历史播放")
    @PostMapping("/record")
    public ResultVO record(@RequestBody HistoryViewParam param) {
        userHistoryViewService.record(param);
        return new ResultVO().success();
    }
    
    @ApiOperation("查询播放历史")
    @PostMapping("/list")
    public ResultVO list(@RequestBody HistoryViewQueryParam param) {
        Page<HistoryViewVO> page = userHistoryViewService.queryPage(param);
        return new ResultVO().success(page);
    }

    @ApiOperation("删除历史记录")
    @PostMapping("/delete")
    public ResultVO delete(@RequestParam("id") Long id) {
        // uid 是被关注者的id
        userHistoryViewService.delete(id);
        return new ResultVO().success();
    }

    @ApiOperation("删除所有历史记录")
    @PostMapping("/clear")
    public ResultVO delete() {
        userHistoryViewService.deleteAll();
        return new ResultVO().success();
    }

}
